package com.gmail.hh.flickrj.sample.android.fragments;


import com.gmail.hh.flickrj.sample.android.R;
import com.gmail.hh.flickrj.sample.android.R.string;
import com.gmail.hh.flickrj.sample.android.R.xml;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;


/**
 * get and put Preferences
 * 
 * @author helmut
 * 
 */
@SuppressLint("NewApi")
public class FragmentSettings extends PreferenceFragment
		implements OnSharedPreferenceChangeListener {

	public static final String TAG = "fragement_settings";
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences); 
    }

	

    // Listener for executing some actions when a setting was changed by the user
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		String maxDistanceKey = getResources().getString(R.string.pref_rotationSteps_key);
        Preference pref = findPreference(key);
        if (key.equals(maxDistanceKey)) {
            // Set summary to be the user-description for the selected value
            pref.setSummary( getResources().getString(R.string.pref_rotationSteps_summary) +
            		" --- changed! Default was " +
            		getResources().getString(R.string.pref_rotationSteps_default) + "." );
        }
    }
    
    @Override
	public void onResume() {
        super.onResume();
        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
	public void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences()
                .unregisterOnSharedPreferenceChangeListener(this);
    }
    
    
}
